package cn.hh.basic.controller;

import cn.hh.basic.execption.BusinessException;
import cn.hh.basic.service.ICodeService;
import cn.hh.basic.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/code")
public class CodeController {

    @Autowired
    private ICodeService codeService;

    /*一定程度下，map可以当作对象使用*/
    @PostMapping("/smsCode")
    public AjaxResult smsCode(@RequestBody Map<String ,String> params) {
        try {
            codeService.smsCode(params);
            return AjaxResult.me();
        } catch (BusinessException e) {
            e.printStackTrace();
            return AjaxResult.me().setMessage("发送失败" + e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setMessage("系统繁忙，稍后重试");
        }
    }
}
